% TABLE 5
clear all;addpath('auxiliar'); addpath('Simulated_Datasets');load SP_SIMULATION_20k.mat
load Taxes_NoGov % 



%% TAXES AT THE ERGODIC
TAUSIM(TAUSIM<0)=0;
Tau_SIM_NOGOV(Tau_SIM_NOGOV<0)=0;
 TAUSIM1=TAUSIM;
 TAUSIM1(TAUSIM1==0)=1e-200;
  Tau_SIM_NOGOV1=Tau_SIM_NOGOV;
 Tau_SIM_NOGOV1(Tau_SIM_NOGOV1==0)=1e-200;
%% Compute Mean TAXES
fprintf(' \n ');
fprintf('The average Taxes are : ');
fprintf('%5.4f \n ',  mean(TAUSIM)*100);
fprintf(' \n ');
fprintf('The average Taxes in a model with not debt are : ');
fprintf('%5.4f \n ',  mean(Tau_SIM_NOGOV1)*100);

%% ADDITIONAL MOMENTS OF THE TAXES
fprintf(' \n ');
fprintf('The standard deviation of Taxes are : ');
fprintf('%5.4f \n ',  std(TAUSIM)*100);
fprintf(' \n ');
fprintf('The standard deviation  of Taxes in a model with not debt are : ');
fprintf('%5.4f \n ',  std(Tau_SIM_NOGOV1)*100);


% CORRELATION WITH OUTPUT
[rho_Y,pv_Y]=corr(TAUSIM,priceSIM+ySIM);
[rho_Y_NoGov,pv_Y_NoGov]=corr(YSIM_SP_NOGOV,Tau_SIM_NOGOV1);

fprintf(' \n ');
fprintf('The correlation of Taxes with output : ');
fprintf('%5.4f \n ', rho_Y) ;
fprintf(' \n ');
fprintf('The correlation of Taxes with output in a model with not debt are : ');
fprintf('%5.4f \n ',rho_Y_NoGov);

% CORRELATION WITH DEBT

[rho_DEBT,pv_DEBT]=corr(TAUSIM,(cte_debtfactor*BGSIM+bSIM)./(priceSIM+ySIM));
[rho_PvDEBT,pv_PvDEBT]=corr(TAUSIM,bSIM./(priceSIM+ySIM));
[rho_PubDEBT,pv_PubDEBT]=corr(TAUSIM,cte_debtfactor*BGSIM./(priceSIM+ySIM));
[rho_DEBT_NoGov,pv_DEBT_NoGov]=corr(bSIM_SP_NOGOV./(YSIM_SP_NOGOV),Tau_SIM_NOGOV1);

fprintf(' \n ');
fprintf('The correlation of Taxes with debt : ');
fprintf('%5.4f \n ',  rho_DEBT);
fprintf(' \n ');
fprintf('The correlation of Taxes with private debt : ');
fprintf('%5.4f \n ',  rho_PvDEBT);
fprintf(' \n ');
fprintf('The correlation of Taxes with public debt : ');
fprintf('%5.4f \n ',  rho_PubDEBT);
fprintf(' \n ');
fprintf('The correlation of Taxes with debt in a model with not debt are : ');
fprintf('%5.4f \n ',  rho_DEBT_NoGov);

%% TABLE
 matrix={'Average tax rate' , mean(TAUSIM)*100, mean(Tau_SIM_NOGOV1)*100;
         'Volatility', std(TAUSIM)*100,std(Tau_SIM_NOGOV1)*100;
         'Correlations','','';
         'Output -Tax rate',rho_Y, rho_Y_NoGov;
         'Total debt - Tax rate' , rho_DEBT, rho_DEBT_NoGov  ;
         'Private debt- Tax Rate', rho_PvDEBT, rho_DEBT_NoGov;
         'Public debt- Tax Rate', rho_PubDEBT, ''};        
  columnLabels = {'', 'Baseline','No public debt'};
matrix2latex(matrix, 'Tables\Table_5.tex', 'columnLabels', columnLabels, 'alignment', 'c','format', '%-6.2f');